<?php
namespace app\index\controller;

use app\index\model\Commentmodel;
use app\index\validate\Comment as validate;
use think\App;

class Comment extends Common
{
    protected $localModel;

    public function __construct(App $app)
    {
        $this->validate = validate::class;
        parent::__construct($app);
        $this->localModel = new Commentmodel();
    }

    public function index(){
        return view();
	}

	public function save(){
        $date = $this->request->request('message/a', []);

        if($msg = $this->checkData($date, 'comment'))  return json(['result'=>'fail', 'title'=>$msg]);
        $res = $this->localModel->saveDataInfo($date);
        if(!$res)  return json(['result'=>'fail', 'title'=>'操作失败！']);

        $this->logsData = [$res, 'add'];
        return json(['result'=>'success', 'title'=>'恭喜您操作成功！', 'url'=>(string)url($this->request->controller().'/index')]);
    }
}
